package com.jsd2412.backend.visitor.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.jsd2412.backend.base.response.JsonResult;
import com.jsd2412.backend.visitor.pojo.dto.VisitorQuery;
import com.jsd2412.backend.visitor.pojo.dto.VisitorSaveParam;
import com.jsd2412.backend.visitor.pojo.vo.VisitorVO;
import com.jsd2412.backend.visitor.service.VisitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "来访管理模块")
public class VisitorController {
    @Autowired
    private VisitorService visitorService;

    @PostMapping("save")
    @ApiOperation("保存来访记录")
    @ApiOperationSupport(order = 10)
    public JsonResult saveVisitor(VisitorSaveParam visitorSaveParam) {
        log.debug("保存来访记录:参数={}", visitorSaveParam);
        visitorService.saveVisitor(visitorSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    @ApiOperation("删除来访记录")
    @ApiOperationSupport(order = 10)
    public JsonResult deleteVisitor(@PathVariable Long id) {
        log.debug("删除来访记录:参数={}", id);
        visitorService.deleteVisitor(id);
        return JsonResult.ok();
    }

    @PostMapping("select")
    @ApiOperation("查询来访记录")
    @ApiOperationSupport(order = 10)
    public JsonResult selectVisitor(VisitorQuery visitorQuery) {
        log.debug("查询来访记录:参数={}", visitorQuery);
        List<VisitorVO> list = visitorService.selectVisitor(visitorQuery);
        return JsonResult.ok(list);
    }

}
